<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');


session_start();
class Absensi extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */
     
     
     
     
     	function __construct(){
		parent::__construct();
        $this->load->model('m_absensi');
        $this->load->library('Datatables');
        $this->load->database();
    }
        
	public function index()
    
	{
	   $this->load->model('mod_master_user');
       
 
                if ($this->session->userdata('type') == 'admin') {
                    redirect('absensi/tampil');
                } else if ($this->session->userdata('type') == 'user'){
                    $a= $this->load->model('m_absensi');
                    $aa["content"] = $this->load->view('absensi/form',$a,true);
                    $this->load->view("absensi/mainUser",$aa);
                }
                
    }
       

    public function form()
    {                
             if ($this->input->post('take_picture')){
                    redirect ('photobooth');
              }
     
                 
     
    }
    
  public function simpan(){
                
            if ($this->input->post('simpan')){ 
                $id_user = $this->session->userdata('id');
                $a= $this->m_absensi->getid($id_user);
                
            if (count($a)==1) {
                                                         
             $this->m_absensi->update($id_user);
            
        
                    
            } else { 
            $jam_masuk = date('Y-m-d H:i:s');
            $path_foto = $this->input->post('path_foto');
            
            $keterangan = $this->input->post('keterangan');
            $data = array ( 'ID_USER'=>$id_user,
                            'JAM_MASUK'=>$jam_masuk,
                            'JAM_PULANG'=>'',
                            'PATH_FOTO'=>$path_foto,
                            'KETERANGAN'=> $keterangan);
            
            $this->m_absensi->save($data);
            }
            redirect('home'); 
        }   
    }
    
      public function update($id_user){
        
            $data3 = $this->m_absensi->getid($id_user);        
            $this->m_absensi->update($id_user);

    }
    
    



    function cari() {
        $this->load->model('m_absensi');
        $data['isi']=$this->m_absensi->caridata();
       //jika data yang dicari tidak ada maka akan keluar informasi 
       //bahwa data yang dicari tidak ada
       if($data['isi']==null) {
        
          print 'maaf data yang anda cari tidak ada atau keywordnya salah';
          print anchor('absensi','kembali');
          }
          else {
            $data4['isi'] = $data['isi']=$this->m_absensi->caridata();
            $data ["content"] = $this->load->view('absensi/admin/table_view',$data4,true); 
            $this->load->view("main",$data);
    }
    }
      
    public function tampil()
    {
        $this->load->model('mod_master_user');	
       
 
                if ($this->session->userdata('type') == 'admin') {
                    $this->load->model('m_absensi');
                    $data2['isi'] = $this->m_absensi->getdata();
                    $data["content"] = $this->load->view('absensi/admin/table_view',$data2,true);
                    $this->load->view("main",$data);
                }
       
    }

    public function json_tampil()
	{
		$this->load->model('m_absensi');
		$data = $this->m_absensi->getdata_json();
        
        $this->load->library('Datatables');
	
		$this->datatables->select('ID_ABSEN,ID_USER,JAM_MASUK,JAM_PULANG,KETERANGAN')
             ->from('absen');
            
             echo $this->datatables->generate();
	}
    
    public function hapus($id_absen) {
        
        $this->load->model('m_absensi');
        $this->m_absensi->hapus($id_absen); 
      
        redirect('absensi/tampil');
   }
   
  
    public function lihatfoto($id_absen){
        $this->load->model('m_absensi');
        $data2['hasil'] = $this->m_absensi->getById($id_absen);
        
        $data["content"] =$this->load->view('absensi/admin/index',$data2,true); 
        $this->load->view("main",$data);
    
    }
    
     public function test($id_user){
        $this->m_absensi->getid($id_user);
     }

    }
    
/* End of file welcome.php */
/* Loc */
